package com.thoughtworks.impersonator.http.verify;

import static org.hamcrest.CoreMatchers.sameInstance;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.handler.codec.http.HttpResponse;
import org.junit.Test;


public class VerifyMessageHandlerTest {

    @Test
    public void shouldStoreResponseForVerification() throws Exception {
        VerifyMessageHandler handler = new VerifyMessageHandler();
        MessageEvent event = mock(MessageEvent.class);
        HttpResponse response = mock(HttpResponse.class);
        Channel channel = mock(Channel.class);
        
        when(event.getMessage()).thenReturn(response);
        when(event.getChannel()).thenReturn(channel);
        
        handler.messageReceived(mock(ChannelHandlerContext.class), event);
        
        assertThat(handler.getResponse(), sameInstance(response));
    }
}
